//2645.构造有效字符串的最少插入数
//https://leetcode.cn/problems/minimum-additions-to-make-valid-string/?envType=daily-question&envId=2024-01-11
class Solution {
public:
    int addMinimum(string word) {
        int n = word.size();
        //计算有多少组abc
        int ret = 1; //默认有一组
        for(int i = 1;i<n;++i)
        {
            //如果上一个字符比当前字符大或者相等则为下一组 不能在同一组
            if(word[i-1] >= word[i]) ++ret;
        }
        
        return (ret*3)-n; //总组数乘以每一组的字符数减去一开始的字符数就是插入字符
    }
}; 